﻿package component.tree.service;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import component.tree.entity.Tree;


public class TreeOrder2 implements ITreeOrder {

	private List dataList = null;

	public List orderTree(List treeList){
		if (treeList == null || treeList.isEmpty()){
			return new ArrayList();
		}
		this.dataList = treeList;
		return this.getOrderTreeList(Tree.ROOT_ID);
	}
	
	//不能删除部分数据
	public List getOrderTreeList(String rootId) {
		List treeList = new ArrayList();
		if (dataList == null || dataList.isEmpty())
			return treeList;
		
		for(int i=0;i<dataList.size();i++){
			Tree tree = (Tree)dataList.get(i);
			String parentId = tree.getParentId();
			if(parentId.equals(rootId)){
				String id = tree.getId();
				List childList = this.getOrderTreeList(id);//递归获取所有子节点
				tree.setChildList(childList);
				treeList.add(tree);
			}
		}
		return treeList;
	}

}
